package com.wwinsoft.framework.entity.security;

import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.GenericGenerator;

/**
 * 会员关系.
 * <p/>
 * 使用JPA annotation定义ORM关系. 使用Hibernate annotation定义JPA 1.0未覆盖的部分.
 *
 * @author calvin
 */
@Entity
//表名与类名不相同时重新定义表名.
@Table(name = "ACT_ID_MEMBERSHIP")
//默认的缓存策略.
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class MemberShip {

    private MemberShipPK key;
    private int type;

    public MemberShip() {
    }

    public MemberShip(MemberShipPK key, int type) {
        this.key = key;
        this.type = type;
    }

    public MemberShip(String userId,String groupId, int type) {
        this.key = new MemberShipPK(userId, groupId);
        this.type = type;
    }

    @EmbeddedId
    @GeneratedValue(generator = "AssignedIDGenerator")
    @GenericGenerator(name = "AssignedIDGenerator", strategy = "assigned")
    public MemberShipPK getKey() {
        return key;
    }

    public void setKey(MemberShipPK key) {
        this.key = key;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    @Transient
    public String getGroupId(){
        return key==null?null:key.getGroupId();
    }

    @Transient
    public String getUserId(){
        return key==null?null:key.getUserId();
    }
}